﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Data;
using System.Collections;

namespace MoneyManagerNET.Presentation.ViewModel
{
    using Model;
    using MoneyManagerNET.Presentation.ViewModel.Base;
    
    public class HomeViewModel:ViewModelBase
    {

        public HomeViewModel()
        {
            TopNumber = 4;
        }

        public DateTime Date { get { return DateTime.Today; } }
        public IEnumerable BankAccounts { 
            get {
                var query = from bacc in App.Storage.Select<IBankAccount>()
                            select new { bacc.Name, Summary=bacc.GetAccountBalance() };
                return query; 
            } 
        }
        public IEnumerable StockAccounts
        {
            get
            {
                //var query = from bacc in App.Storage.Select<IStockAccount>()
                //            select new { bacc.Name, Summary = bacc.GetTotal() };
                //return query;
                //TODO: uncomment
                return null;
            }
        }

        public decimal CurrentMonthIncome {
            get {
                var income = App.Storage.Select<ITransaction>(tr => tr.FromAccount == null).Sum(tr=>tr.Amount);

                return income;
            }
        }

        public decimal CurrentMonthExpense
        {
            get
            {
                var expense = App.Storage.Select<ITransaction>(tr => tr.ToAccount == null).Sum(tr => tr.Amount);

                return expense;
            }
        }

        public int TransactionCount { get { return App.Service.CountTotalTransactions(); } }


        public int TopNumber { get; set; }
        public IEnumerable<ITransaction> TopTransactions {
            get {
                return App.Service.GetTopTransactions(TopNumber);
            }
        }

        

    }
}
